#!/bin/sh

set -e
set -u

if [ $# -lt 2 ] ; then
    echo 'Usage: upload-release VERSION [DIR]'
    echo 'Must be called in directory with binaries or with path'
    exit 1
fi
REL=$1

if [ $# -gt 1 ] ; then
    cd "$2"
fi

# Upload to our file server
sftp -P 11022 files@klutz.phpmyadmin.net -b - <<EOT
cd /mnt/storage/files/phpMyAdmin
mkdir $REL
cd $REL
put phpMyAdmin-$REL-all-languages.tar.bz2
put phpMyAdmin-$REL-english.tar.bz2
put phpMyAdmin-$REL-all-languages.tar.xz
put phpMyAdmin-$REL-english.tar.xz
put phpMyAdmin-$REL-all-languages.tar.gz
put phpMyAdmin-$REL-english.tar.gz
put phpMyAdmin-$REL-all-languages.zip
put phpMyAdmin-$REL-english.zip
put phpMyAdmin-$REL-all-languages.7z
put phpMyAdmin-$REL-english.7z
put phpMyAdmin-$REL-all-languages.tar.bz2.asc
put phpMyAdmin-$REL-english.tar.bz2.asc
put phpMyAdmin-$REL-all-languages.tar.xz.asc
put phpMyAdmin-$REL-english.tar.xz.asc
put phpMyAdmin-$REL-all-languages.tar.gz.asc
put phpMyAdmin-$REL-english.tar.gz.asc
put phpMyAdmin-$REL-all-languages.zip.asc
put phpMyAdmin-$REL-english.zip.asc
put phpMyAdmin-$REL-all-languages.7z.asc
put phpMyAdmin-$REL-english.7z.asc
put phpMyAdmin-$REL-all-languages.tar.bz2.sha1
put phpMyAdmin-$REL-english.tar.bz2.sha1
put phpMyAdmin-$REL-all-languages.tar.xz.sha1
put phpMyAdmin-$REL-english.tar.xz.sha1
put phpMyAdmin-$REL-all-languages.tar.gz.sha1
put phpMyAdmin-$REL-english.tar.gz.sha1
put phpMyAdmin-$REL-all-languages.zip.sha1
put phpMyAdmin-$REL-english.zip.sha1
put phpMyAdmin-$REL-all-languages.7z.sha1
put phpMyAdmin-$REL-english.7z.sha1
put phpMyAdmin-$REL-all-languages.tar.bz2.md5
put phpMyAdmin-$REL-english.tar.bz2.md5
put phpMyAdmin-$REL-all-languages.tar.xz.md5
put phpMyAdmin-$REL-english.tar.xz.md5
put phpMyAdmin-$REL-all-languages.tar.gz.md5
put phpMyAdmin-$REL-english.tar.gz.md5
put phpMyAdmin-$REL-all-languages.zip.md5
put phpMyAdmin-$REL-english.zip.md5
put phpMyAdmin-$REL-all-languages.7z.md5
put phpMyAdmin-$REL-english.7z.md5
put phpMyAdmin-$REL-notes.html
EOT

# Sync files to CDN
ssh -p 11022 files@klutz.phpmyadmin.net ./bin/sync-files-cdn
